var xmlhttp;

function initAjax()
{
    if(window.XMLHttpRequest)
    {
        return new XMLHttpRequest();
    }
    else if(window.ActiveXObject)
    {
        return new ActiveXObject("Microsoft.XMLHTTP");
    }
    else
    {
        alert("Your browser does not support AJAX!");
        return null;
    }
}

var http = initAjax();
var lmenu = initAjax();
var rmenu = initAjax();
var chat = initAjax();
var chat2 = initAjax();
var misc = initAjax();
var recap = initAjax();

function sendData(url)
{
    if(actioninprogress == 0 && ccheck == 0)
    {
        whichHandle = 1;
        ccheck = 1;
        document.getElementById('actiontimer').innerHTML = 'Waiting...';
        http.open("GET",url,true);
        http.setRequestHeader("X-Requested-With", "tlrreq");
        http.send(null);
        http.onreadystatechange=handleResponse1;
    }
    else
    {
        if(document.getElementById('contentselect'))
        {
            document.getElementById('contentselect').selectedIndex = cdd;
        }
        alert("Please wait until your previous action is complete.");
    }
}

function sendLMenu(url)
{
    if(lcheck == 0)
    {
        lcheck = 1;
        document.getElementById('leftloader').innerHTML = 'Waiting...';
        lmenu.open("GET",url,true);
        lmenu.setRequestHeader("X-Requested-With", "tlrreq");
        lmenu.send(null);
        lmenu.onreadystatechange=handleResponse2;
    }
    else
    {
        document.getElementById('leftselect').selectedIndex = ldd;
        alert("Please wait until your previous action is complete.");
    }
}

function sendRMenu(url)
{
    if(rcheck == 0)
    {
        rcheck = 1;
        document.getElementById('rightloader').innerHTML = 'Waiting...';
        rmenu.open("GET",url,true);
        rmenu.setRequestHeader("X-Requested-With", "tlrreq");
        rmenu.send(null);
        rmenu.onreadystatechange=handleResponse3;
    }
    else
    {
        document.getElementById('rightselect').selectedIndex = rdd;
        alert("Please wait until your previous action is complete.");
    }
}

function sendChat(url)
{
    chat.open("GET",url,true);
    chat.setRequestHeader("X-Requested-With", "tlrreq");
    chat.send(null);
    chat.onreadystatechange=handleResponse4;
}

function sendChat2(url, params)
{
    chat2.open("POST",url,true);
    chat2.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    chat2.setRequestHeader("Content-length", params.length);
    chat2.setRequestHeader("Connection", "close");
    chat2.setRequestHeader("X-Requested-With", "tlrreq");
    chat2.send(params);
    chat2.onreadystatechange=handleResponse5;
}

function sendMisc(url, params)
{
    misc.open("POST",url,true);
    misc.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    misc.setRequestHeader("Content-length", params.length);
    misc.setRequestHeader("Connection", "close");
    misc.setRequestHeader("X-Requested-With", "tlrreq");
    misc.send(params);
    misc.onreadystatechange=handleResponse6;
}

function sendRecap(url, params)
{
    whichHandle = 2;
    recap.open("POST",url,true);
    recap.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    recap.setRequestHeader("Content-length", params.length);
    recap.setRequestHeader("Connection", "close");
    recap.setRequestHeader("X-Requested-With", "tlrreq");
    recap.send(params);
    recap.onreadystatechange=handleResponse1;
}

function handleResponse1()
{
    if((http.readyState == 4 && whichHandle == 1) || (recap.readyState == 4 && whichHandle == 2))
    {
        ccheck = 0;
        if(whichHandle == 1)
        {
            var response = http.responseText;
        }
        else
        {
            var response = recap.responseText;
        }
        var update = new Array();
        
        if(response.indexOf('|' != -1))
        {
            update = response.split('|');
            
            var totalUpdates = (update.length / 2);
            var currentUpdate = 1;
            var var1 = 0;
            var var2 = 1;
            
            while(currentUpdate <= totalUpdates)
            {
                if(update[var1] == 'at')
                {
                    actioninprogress = 1;
                    actiontimer(update[var2]);
                }
                else if(update[var1] == 'special')
                {
                    if(update[var2] == 'aterror')
                    {
                        alert("Please wait until your previous action is complete!");
                        if(document.getElementById('battlebutton'))
                        {
                            document.getElementById('battlebutton').disabled = false;
                        }
                    }
                    if(update[var2] == 'banned')
                    {
                        alert("Your account is currently banned. Check your e-mail for further details.");
                        window.location = 'http://www.thelostrunes.com/';
                    }
                    if(update[var2] == 'autoattack')
                    {
                        autoattack = 1;
                    }
                    if(update[var2] == 'disautoattack')
                    {
                        autoattack = 0;
                    }
                    if(update[var2] == 'secchkfail')
                    {
                        alert("You have failed too many security checks and have been logged out.");
                        window.location = 'http://www.thelostrunes.com/index.php?logout';
                    }
                }
                else if(update[var1] == 'specialmobid')
                {
                    autoattackid = update[var2];
                }
                else if(update[var1] == 'tradeskills')
                {
                    actioninprogress = 0;
                    init_tradeskill(update[var2]);
                }
                else if(update[var1] == 'securitycheck')
                {
                    actiontimer(2000);
                    showRecaptcha('recaptcha_div');
                }
                else
                {
                    document.getElementById(update[var1]).innerHTML = update[var2];
                }
                currentUpdate = currentUpdate + 1;
                var1 = var1 + 2;
                var2 = var2 + 2;
            }
            
            if (actioninprogress == 0)
            {
                document.getElementById('actiontimer').innerHTML = '0.0';
            }
        }
    }
}

function handleResponse2()
{
    if(lmenu.readyState == 4)
    {
        lcheck = 0;
        document.getElementById('leftloader').innerHTML = '';
        
        var response = lmenu.responseText;
        var update = new Array();
        
        if(response.indexOf('|' != -1))
        {
            update = response.split('|');
            
            var totalUpdates = (update.length / 2);
            var currentUpdate = 1;
            var var1 = 0;
            var var2 = 1;
            
            while(currentUpdate <= totalUpdates)
            {
                document.getElementById(update[var1]).innerHTML = update[var2];
                currentUpdate = currentUpdate + 1;
                var1 = var1 + 2;
                var2 = var2 + 2;
            }
        }
    }
}

function handleResponse3()
{
    if(rmenu.readyState == 4)
    {
        rcheck = 0;
        document.getElementById('rightloader').innerHTML = '';
        
        var response = rmenu.responseText;
        var update = new Array();
        
        if(response.indexOf('|' != -1))
        {
            update = response.split('|');
            
            var totalUpdates = (update.length / 2);
            var currentUpdate = 1;
            var var1 = 0;
            var var2 = 1;
            
            while(currentUpdate <= totalUpdates)
            {
                document.getElementById(update[var1]).innerHTML = update[var2];
                currentUpdate = currentUpdate + 1;
                var1 = var1 + 2;
                var2 = var2 + 2;
            }
        }
    }
}

function handleResponse4()
{
    if(chat.readyState == 4)
    {
        var response = chat.responseText;
        var update = new Array();
        
        if(response.indexOf('|' != -1))
        {
            update = response.split('|');
            update.shift();
            
            var totalUpdates = update.length;
            var currentUpdate = 1;
            while (currentUpdate <= totalUpdates)
            {
                chatArray.shift();
                chatArray.push(update[currentUpdate-1]);
                currentUpdate += 1;
            }
            
            var chatmsg = '';
            for (var i=chatArray.length-1; i>=0; --i)
            {
                chatmsg = chatmsg + chatArray[i] + '<br />';
            }
            
            document.getElementById('chat').innerHTML = chatmsg;
        }
        
        chatcalled = 0;
        clearTimeout(disablechattimer);
        clearTimeout(chatcalledtimer);
    }
}

function handleResponse5()
{
    if(chat2.readyState == 4)
    {
        if (chatsubmitted == 1)
        {
            chatsubmitted = 0;
            document.getElementById('chatinput').value = '';
        }
    }
}

function handleResponse6()
{
    if(misc.readyState == 4)
    {
        var response = misc.responseText;
        var update = new Array();
        
        if(response.indexOf('|' != -1))
        {
            update = response.split('|');
            
            var totalUpdates = (update.length / 2);
            var currentUpdate = 1;
            var var1 = 0;
            var var2 = 1;
            
            while(currentUpdate <= totalUpdates)
            {
                document.getElementById(update[var1]).innerHTML = update[var2];
                currentUpdate = currentUpdate + 1;
                var1 = var1 + 2;
                var2 = var2 + 2;
            }
        }
    }
}

function leftMenu()
{
    document.getElementById('leftloader').innerHTML = 'Loading...';
    var ltype = document.getElementById('leftselect').value;
    if (lcheck == 0)
    {
        ldd = ltype-1;
    }
    if (ltype == 1) { sendLMenu('g_left.php?mod=attributes'); }
    if (ltype == 2) { sendLMenu('g_left.php?mod=skills'); }
    if (ltype == 3) { sendLMenu('g_left.php?mod=tradeskills'); }
    if (ltype == 4) { sendLMenu('g_left.php?mod=statistics'); }
}

function rightMenu()
{
    document.getElementById('rightloader').innerHTML = 'Loading...';
    var rtype = document.getElementById('rightselect').value;
    if (rcheck == 0)
    {
        rdd = rtype-1;
    }
    if (rtype == 1) { sendRMenu('g_right.php?mod=equipped'); }
    if (rtype == 3) { sendRMenu('g_right.php?mod=runes'); }
    if (rtype == 4) { sendRMenu('g_right.php?mod=dungeonkeys'); }
    if (rtype == 5) { sendRMenu('g_right.php?mod=miscitems'); }
    if (rtype == 6) { sendRMenu('g_right.php?mod=collections'); }

}
function contentMenu()
{
    var ctype = document.getElementById('contentselect').value;
    if (actioninprogress == 0 && ccheck == 0)
    {
        cdd = ctype-1;
    }
    if (ctype == 1) { sendData('g_content.php?mod=showenemies'); }
    if (ctype == 2) { sendData('g_content.php?mod=showtravel'); }
    if (ctype == 3) { sendData('clan.php?mod=clan'); }
    if (ctype == 4) { sendData('g_content.php?mod=tradeskills'); }
    if (ctype == 5) { sendData('g_content.php?mod=quests'); }
    if (ctype == 6) { sendData('g_content.php?mod=market'); }
    if (ctype == 7) { sendData('land.php?mod=land'); }
    if (ctype == 8) { sendData('g_content.php?mod=crafting'); }
    if (ctype == 9) { sendData('g_content.php?mod=milestones'); }
    if (ctype == 10) { sendData('g_content.php?mod=arena&avar=1'); }
    if (ctype == 11) { sendData('g_content.php?mod=log'); }
    if (ctype == 12) { sendData('g_content.php?mod=pref'); }
}

function go(loc)
{
    if (loc >= 1 && loc <= 5) { sendData('misc.php?mod=go&loc='+loc); }
}

function travel(loc)
{
    sendData('g_content.php?mod=showtravel&loc='+loc);
}

function battle(btype, autoattack)
{
    document.getElementById('battlebutton').disabled = true;
    if (btype == 0)
    {
        var mobid = document.getElementById('mob').value;
        sendData('battle.php?id='+mobid+'&autoattack='+autoattack);
    }
    else if (btype == 10)
    {
        sendData('battle.php?id='+autoattack+'&autoattack=0');
    }
    else
    {
        sendData('battle.php');
    }
}

function continueBattle(id)
{
    document.getElementById('battlebutton').disabled = true;
    sendData('misc.php?mod=conbattle');
}

function view(vtype, id)
{
    if (vtype == 1) { sendRMenu('misc.php?mod=getruneinfo&id='+id); }
    if (vtype == 2) { sendRMenu('misc.php?mod=getequipmentinfo&id='+id); }
    if (vtype == 3) { sendRMenu('misc.php?mod=getequipmentinfo&id='+id+'&upgrade'); }
    if (vtype == 4) { sendLMenu('misc.php?mod=getskillinfo&id='+id); }
    if (vtype == 5) { sendLMenu('misc.php?mod=getskillinfo&id='+id+'&upgrade=1'); }
    if (vtype == 100) { sendRMenu('misc.php?mod=getequipmentinfo&id=0&view=100'); }
}

function setRune(id, etype)
{
    if (etype == 1)
    {
        sendRMenu('g_right.php?mod=runes&id='+id+'&etype='+etype);
    }
    else if(etype == 6)
    {
        sendRMenu('misc.php?mod=marketrune&id='+id);
    }
    else if(etype == 5)
    {
        var ramount = document.getElementById('marketrunesell').value;
        sendRMenu('g_right.php?mod=runes&id='+id+'&etype='+etype+'&amount='+ramount);
    }
    else
    {   
        sendRMenu('g_right.php?mod=runes&id='+id+'&etype='+etype);
    }
}

function getKey(id, ktype)
{
    if(ktype == 3)
    {
        var ramount = document.getElementById('marketkeysell').value;
        sendRMenu('g_right.php?mod=dungeonkeys&id='+id+'&ktype='+ktype+'&amount='+ramount);
    }
    else
    {
        sendRMenu('g_right.php?mod=dungeonkeys&id='+id+'&ktype='+ktype);
    }
}

function marketChange()
{
    var mtype = document.getElementById('marketchange').value;
    sendData('g_content.php?mod=market&mtype='+mtype);
}

function marketBuy(id, mtype)
{
    sendData('g_content.php?mod=market&id='+id+'&mtype='+mtype+'&buy');
}

function milestoneChange()
{
    var mtype = document.getElementById('milestonechange').value;
    sendData('g_content.php?mod=milestones&mtype='+mtype);
}

function craftingChange()
{
    var ctype = document.getElementById('craftingchange').value;
    sendData('g_content.php?mod=crafting&ctype='+ctype);
}

function leaveDungeon()
{
    sendData('misc.php?mod=leavedungeon');
}

function generateQuest(qtype)
{
    if(qtype == 2)
    {
        var questmob = document.getElementById('questmob').value;
    }
    else
    {
        var questmob = 10;
    }
    sendData('g_content.php?mod=quests&generate&questmob='+questmob);
}

function completeQuest()
{
    sendData('g_content.php?mod=quests&complete');
}

function callChat()
{
    if (chatcalled == 0)
    {
        chatcalled = 1;
        chatcalledtimer = setTimeout('chatcalled = 0', 15000);
        sendChat('chat.php');
    }
}

function submitChat()
{
    var cmsg = document.getElementById('chatinput').value;
    if (cmsg.match(/(\||#)/g))
    {
        alert("Messages cannot contain the characters | or #.");
    }
    else if(cmsg.match(/^\/view/))
    {
        document.getElementById('chatinput').value = '';
        viewPlayer(cmsg.substring(6));
    }
    else if(chatsubmitted == 1)
    {
        alert("Please wait until your previous message has been sent.");
    }
    else
    {
        chatsubmitted = 1;
        disablechattimer = setTimeout('chatsubmitted = 0;', 3000);
        sendChat2('misc.php?mod=chat', 'msg='+cmsg);
    }
}

function submitSecChk(sctype, scvar)
{
    if(scvar == 0) { clearTimeout(secchktimer); }
    var ans = document.getElementById('secchkvalue').value;
    sendData('misc.php?mod=securitycheck&ans='+ans+'&sctype='+sctype+'&scvar='+scvar);
}

function checkPOnline()
{
    sendMisc('misc.php?mod=playersonline', '');
}

function openNav(nvar)
{
    document.getElementById('mainpopup').style.visibility = 'visible';
    if(nvar == 1) { sendMisc('credits.php?mod=purchase', ''); }
    if(nvar == 2) { sendMisc('mainnav.php?mod=ponline', ''); }
    if(nvar == 3) { sendMisc('mainnav.php?mod=ranks&ranking=1', ''); }
    if(nvar == 4) { sendMisc('mainnav.php?mod=tranks&ranking=1', ''); }
    if(nvar == 5) { sendMisc('mainnav.php?mod=referral', ''); }
    if(nvar == 6) { sendMisc('mainnav.php?mod=changerace', ''); }
    if(nvar == 7) { sendMisc('mainnav.php?mod=offers', ''); }
    if(nvar == 8) { sendMisc('mainnav.php?mod=guide', ''); }
    if(nvar == 9) { sendMisc('mainnav.php?mod=rules', ''); }
    if(nvar == 10) { sendMisc('mainnav.php?mod=updates', ''); }
    if(nvar == 11) { sendMisc('mainnav.php?mod=rpstore', ''); }
}

function mainNav(nvar)
{
    if(nvar == 1) { sendMisc('credits.php?mod=purchase', ''); }
    if(nvar == 2) { sendMisc('credits.php?mod=permupg', ''); }
    if(nvar == 3) { sendMisc('credits.php?mod=tempupg', ''); }
    if(nvar == 4) { sendMisc('credits.php?mod=misc', ''); }
    if(nvar == 101) { sendMisc('mainnav.php?mod=ranks&ranking=1', ''); }
    if(nvar == 102) { sendMisc('mainnav.php?mod=ranks&ranking=2', ''); }
    if(nvar == 103) { sendMisc('mainnav.php?mod=ranks&ranking=3', ''); }
    if(nvar == 104) { sendMisc('mainnav.php?mod=ranks&ranking=4', ''); }
    if(nvar == 111) { sendMisc('mainnav.php?mod=ranks&ranking=5', ''); }
    if(nvar == 112) { sendMisc('mainnav.php?mod=ranks&ranking=6', ''); }
    if(nvar == 113) { sendMisc('mainnav.php?mod=ranks&ranking=7', ''); }
    if(nvar == 114) { sendMisc('mainnav.php?mod=ranks&ranking=8', ''); }
    if(nvar == 121) { sendMisc('mainnav.php?mod=ranks&ranking=9', ''); }
    if(nvar == 122) { sendMisc('mainnav.php?mod=ranks&ranking=10', ''); }
    if(nvar == 123) { sendMisc('mainnav.php?mod=ranks&ranking=11', ''); }
    if(nvar == 124) { sendMisc('mainnav.php?mod=ranks&ranking=12', ''); }
    if(nvar == 131) { sendMisc('mainnav.php?mod=ranks&ranking=13', ''); }
    if(nvar == 132) { sendMisc('mainnav.php?mod=ranks&ranking=14', ''); }
    if(nvar == 151) { sendMisc('mainnav.php?mod=tranks&ranking=1', ''); }
    if(nvar == 152) { sendMisc('mainnav.php?mod=tranks&ranking=2', ''); }
}

function spendCredits(cvar)
{
    if(cvar == 1) { sendMisc('credits.php?mod=permupg&item=doublerune', ''); }
    if(cvar == 2) { sendMisc('credits.php?mod=permupg&item=questhelper', ''); }
    if(cvar >= 10 && cvar <= 12) { sendMisc('credits.php?mod=permupg&item='+cvar, ''); }
    if(cvar >= 21 && cvar <= 24) { sendMisc('credits.php?mod=tempupg&item='+cvar, ''); }
    if(cvar == 101) { sendMisc('credits.php?mod=misc&item=101', ''); }
    if(cvar == 102) { sendMisc('credits.php?mod=misc&item=102', ''); }
    if(cvar >= 111 && cvar <= 113) { sendMisc('credits.php?mod=misc&item='+cvar, ''); }
    if(cvar >= 121 && cvar <= 122) { sendMisc('credits.php?mod=misc&item='+cvar, ''); }
    if(cvar == 151) { sendMisc('credits.php?mod=misc&item=151&type=1', ''); }
    if(cvar == 152) { sendMisc('credits.php?mod=misc&item=151&type=2', ''); }
    if(cvar == 153) { sendMisc('credits.php?mod=misc&item=151&type=3', ''); }
    if(cvar == 154) { sendMisc('credits.php?mod=misc&item=151&type=4', ''); }
    if(cvar == 155) { sendMisc('credits.php?mod=misc&item=151&type=5', ''); }
    if(cvar >= 1001 && cvar <= 1020) { sendMisc('credits.php?mod=misc&item='+cvar, ''); }
    if(cvar >= 1101 && cvar <= 1115) { sendMisc('credits.php?mod=misc&item='+cvar, ''); }
    if(cvar == 1500) { sendMisc('credits.php?mod=misc&item=1500', ''); }
}

function transcend()
{
    sendData('mainnav.php?mod=changerace&upg');
}

function marketCredits(cvar, id)
{
    if(cvar == 1)
    {
        var credits = document.getElementById('credits').value;
        var price = document.getElementById('price').value;
        sendData('g_content.php?mod=market&mtype=3&cvar=1&credits='+credits+'&price='+price);
    }
    if(cvar == 2)
    {
        sendData('g_content.php?mod=market&mtype=3&cvar=2&id='+id);
    }
}

function marketPlatinum(cvar, id)
{
    if(cvar == 1)
    {
        var platinum = document.getElementById('platinum').value;
        var price = document.getElementById('price').value;
        sendData('g_content.php?mod=market&mtype=4&cvar=1&platinum='+platinum+'&price='+price);
    }
    if(cvar == 2)
    {
        sendData('g_content.php?mod=market&mtype=4&cvar=2&id='+id);
    }
}

function marketShards(cvar, id)
{
    if(cvar == 1)
    {
        var shards = document.getElementById('shards').value;
        var price = document.getElementById('price').value;
        sendData('g_content.php?mod=market&mtype=5&cvar=1&shards='+shards+'&price='+price);
    }
    if(cvar == 2)
    {
        sendData('g_content.php?mod=market&mtype=5&cvar=2&id='+id);
    }
}

function marketRes(cvar, cvar2, id)
{
    if(cvar == 1)
    {
        var res = document.getElementById('res').value;
        var price = document.getElementById('price').value;
        sendData('g_content.php?mod=market&mtype='+cvar2+'&cvar=1&res='+res+'&price='+price);
    }
    if(cvar == 2)
    {
        sendData('g_content.php?mod=market&mtype='+cvar2+'&cvar=2&id='+id);
    }
}

function tsNav(tvar, id)
{
    sendData('g_content.php?mod=tradeskills&tvar='+tvar+'&ts='+id);
}

function submitSecChk()
{
    var rec1 = Recaptcha.get_challenge();
    var rec2 = Recaptcha.get_response();
    var sctype = document.getElementById('sctype').value;
    
    sendRecap('misc.php?mod=recaptcha', '&rec1='+rec1+'&rec2='+rec2+'&sctype='+sctype);
}

function createClan()
{
    var clanname = document.getElementById('clanname').value;
    var clantag = document.getElementById('clantag').value;
    
    sendData('clan.php?mod=clan&create&clanname='+clanname+'&clantag='+clantag);
}

function clanInv(cvar, clan)
{
    if(cvar == 1) { sendData('clan.php?mod=clan&acceptinvite&clan='+clan); }
    if(cvar == 2) { sendData('clan.php?mod=clan&declineinvite&clan='+clan); }
}

function goClan(cvar)
{
    if(cvar == 1) { sendData('clan.php?mod=clan'); }
    if(cvar == 2) { sendData('clan.php?mod=members'); }
    if(cvar == 3) { sendData('clan.php?mod=clanlog'); }
    if(cvar == 4) { sendData('clan.php?mod=donate'); }
    if(cvar == 5) { sendData('clan.php?mod=buildings'); }
    if(cvar == 6) { sendData('clan.php?mod=stats'); }
    if(cvar == 7) { sendData('clan.php?mod=skills'); }
    if(cvar == 50) { sendData('clan.php?mod=leaveclan'); }
    if(cvar == 51) { sendData('clan.php?mod=leaveclan&confirm'); }
    if(cvar == 101) { sendData('clan.php?mod=clanprefs'); }
    if(cvar == 110) { sendData('clan.php?mod=disbandclan'); }
}

function clanFunc(cvar, userid)
{
    if(cvar == 1) { sendData('clan.php?mod=members&viewmem&id='+userid); }
    if(cvar == 50) { sendData('clan.php?mod=members&kickmem&id='+userid); }
}

function clanDonate()
{
    var dgold = document.getElementById('gold').value;
    var dplatinum = document.getElementById('platinum').value;
    var ddiamonds = document.getElementById('diamonds').value;
    var dcredits = document.getElementById('credits').value;
    var dfood = document.getElementById('food').value;
    var dwood = document.getElementById('wood').value;
    var diron = document.getElementById('iron').value;
    var dstone = document.getElementById('stone').value;
    
    sendData('clan.php?mod=donate&donate&gold='+dgold+'&platinum='+dplatinum+'&diamonds='+ddiamonds+'&credits='+dcredits+'&food='+dfood+'&wood='+dwood+'&iron='+diron+'&stone='+dstone);
}

function clanDisband()
{
    var em = document.getElementById('clandisbandem').value;
    sendData('clan.php?mod=disbandclan&confirm&em='+em);
}

function clanTaxes()
{
    var gtax = document.getElementById('goldtax').value;
    var etax = document.getElementById('exptax').value;
    sendData('clan.php?mod=clanprefs&gtax='+gtax+'&etax='+etax);
}

function upgBuilding(uvar)
{
    sendData('clan.php?mod=buildings&upgrade='+uvar);
}

function upgClanSkill(uvar)
{
    sendData('clan.php?mod=skills&upgrade='+uvar);
}

function purchaseCollection(pvar)
{
    sendRMenu('g_right.php?mod=collections&c='+pvar);
}

function craftRune(cvar)
{
    sendData('g_content.php?mod=crafting&rune='+cvar);
}

function destroyRunes(dvar)
{
    if(dvar == 1) { var cfrm = confirm('Destroy all runes for rune shards: Are you sure?'); if(cfrm) { sendData('g_right.php?mod=runes&rdestroy'); } }
    if(dvar == 2) { var cfrm = confirm('Sell all runes for platinum: Are you sure?'); if(cfrm) { sendData('g_right.php?mod=runes&rdestroy2'); } }
    if(dvar == 3) { var cfrm = confirm('Sell all common runes for platinum: Are you sure?'); if(cfrm) { sendData('g_right.php?mod=runes&rdestroy3'); } }
}

function changeGender()
{
    sendData('mainnav.php?mod=changerace&gender');
}

function joinArena(avar)
{
    sendData('g_content.php?mod=arena&avar=1&arenaid='+avar);
}

function changePassword()
{
    var cp1 = document.getElementById('cp1').value;
    var cp2 = document.getElementById('cp2').value;
    var cp3 = document.getElementById('cp3').value;
    sendMisc('g_content.php?mod=pref&cp', 'cp1='+cp1+'&cp2='+cp2+'&cp3='+cp3);
}

function setCustTax()
{
    var gtax = document.getElementById('gtax').value;
    var etax = document.getElementById('etax').value;
    sendMisc('g_content.php?mod=pref&sct&gtax='+gtax+'&etax='+etax, '');
}

function setChatSize()
{
    var chatsize = document.getElementById('chatsize').value;
    sendMisc('g_content.php?mod=pref&scs&chatsize='+chatsize, '');
}

function openPouch()
{
    sendMisc('g_left.php?mod=statistics&openpouch=1', '');
}

function useToken()
{
    sendMisc('g_left.php?mod=statistics&usetoken=1', '');
}

function setCoLeader()
{
    var colead = document.getElementById('colead').value;
    sendData('clan.php?mod=clanprefs&colead='+colead);
}

function occupyTile()
{
    sendData('land.php?mod=land&occupy');
}

function spawn()
{
    var svar = document.getElementById('spawnid').value;
    sendData('land.php?mod=land&spawn='+svar);
}

function attackBeast(btype, bid)
{
    if(document.getElementById('battlebutton'))
    {
        document.getElementById('battlebutton').disabled = true;
    }
    sendData('bossbattle.php?btype='+btype+'&bid='+bid);
}

function climbTower()
{
    sendData('misc.php?mod=climbtower');
}

function renameEquipment(eqid)
{
    var eqname = document.getElementById('eqname').value;
    sendData('misc.php?mod=renameeq&id='+eqid+'&eqname='+eqname);
}

function spawnClanBoss()
{
    sendData('clan.php?mod=stats&spawnboss');
}

function changeRank()
{
    var rnk = document.getElementById('changerank').value;
    sendData('g_content.php?mod=pref&chgrnk='+rnk);
}

function landNav(lvar)
{
    if(lvar == 0) { sendData('land.php?mod=land'); }
    if(lvar == 1) { sendData('land.php?mod=buildings'); }
    if(lvar == 2) { sendData('land.php?mod=population'); }
    if(lvar == 3) { sendData('land.php?mod=army'); }
    if(lvar == 4) { sendData('land.php?mod=unsettle'); }
    if(lvar == 5) { sendData('land.php?mod=mland'); }
    if(lvar == 6) { sendData('land.php?mod=totems'); }
}

function landUpgrade(lvar)
{
    if(lvar >= 1 && lvar <= 5) { sendData('land.php?mod=mland&upg='+lvar); }
}

function landUnsettle()
{
    var uvar = document.getElementById('landunsettle').value;
    sendData('land.php?mod=unsettle&confirm&uvar='+uvar);
}

function landTrain()
{
    var wtype = document.getElementById('wtype').value;
    var wamount = document.getElementById('wamount').value;
    sendData('land.php?mod=population&train=1&wtype='+wtype+'&wamount='+wamount);
}

function landBuild(avar, bvar)
{
    if(avar == 1) { sendData('land.php?mod=buildings&build='+bvar); }
    if(avar == 2) { sendData('land.php?mod=buildings&active='+bvar); }
}

function teleport()
{
    sendData('misc.php?mod=go&teleport');
}

function assignWorkers()
{
    var wvar = document.getElementById('popassign').value;
    sendData('land.php?mod=population&assignpop&wvar='+wvar);
}

function landDeposit()
{
    var food = document.getElementById('food').value;
    var wood = document.getElementById('wood').value;
    var iron = document.getElementById('iron').value;
    var stone = document.getElementById('stone').value;
    sendData('land.php?mod=population&landdeposit&food='+food+'&wood='+wood+'&iron='+iron+'&stone='+stone);
}

function landAttack()
{
    var sol = document.getElementById('sol').value;
    sendData('land.php?mod=attack&sol='+sol);
}

function rp(rvar)
{
    sendData('mainnav.php?mod=rpstore&rvar='+rvar);
}
